<?php
/**
 * Name: IndexController.php.
 * Author: JiaMeng <666@majiameng.com>
 * Date: 2018/4/16 14:12
 * Description: IndexController.php.
 */
namespace App\Http\Controllers;

use App\Jobs\OrderCallbackJob;
use App\Models\MysqlDb\PaymentOrderModel;
use App\Models\StatusCode;
use App\Services\CommonReturn;
use Illuminate\Http\Request;

class IndexController extends BaseController
{

    /**
     * @return void
     */
    public function index(){
        CommonReturn::success();
    }

    /**
     * 创建订单回调任务
     * @param Request $request
     * @return void
     */
    public function orderCallback(Request $request)
    {
        $out_trade_no = $request->get('out_trade_no',null);
        if(empty($out_trade_no)){
            CommonReturn::fail(StatusCode::COMMON_PARAM_MISS);
        }
        $order = PaymentOrderModel::where('out_trade_no',$out_trade_no)->first();
        if(empty($order)){
            CommonReturn::fail(StatusCode::COMMON_NO_DATA_EXIST);
        }
        OrderCallbackJob::dispatch($order);
        CommonReturn::success($order);
    }


}
